const URL = "https://v.cjveg.com/api";
//模糊查询

export function keyselect(num, cb) {
  wx.request({
    url: URL + '/search?pagesize=20&pageindex=1&query=长江',
    data: {
      // cateid: id,
      // pagesize: pagesize,
      // page: page
    },
    success: function(res) {
      cb(res.data, id);
      console.log(res.data);
    }
  })
}


// 获取各个栏目最新视频列表
export function select(id, pagesize, page, cb) {
  wx.request({
    url: URL + '/GetVideoList?',
    data: {
      cateid: id,
      pagesize: pagesize,
      page: page
    },
    success: function(res) {
      cb(res.data, id);

    }
  })
}


// 获取各个栏目最新视频列表
export function getViedoList(id, pagesize, page, cb) {
  wx.request({
    url: URL + '/GetVideoList?',
    data: {
      cateid: id,
      pagesize: pagesize,
      page: page
    },
    success: function(res) {
      cb(res.data, id);
      // console.log(res.data);
    }
  })
}

export function getVideoListPromise(id, pagesize, page) {
  return new Promise(function(resolve, reject) {
    wx.request({
      url: URL + '/GetVideoList?',
      data: {
        cateid: id,
        pagesize: pagesize,
        page: page
      },
      success: function(res) {
        resolve(res.data, id);
      },
      fail: function(res) {
        reject(res);
      }
    })
  })
}
// 获取整个网站的最热视频
export function getHotVideoList(num, cb) {
  wx.request({
    url: URL + '/GetHotVideoList?',
    data: {
      count: 6
    },
    success: function(res) {
      cb(res.data)
    }
  })
}
// 获取整个网站的最新视频
export function getNewVideoList(pagesize, page, cb) {
  wx.request({
    url: URL + '/GetNewVideoList?',
    data: {
      pagesize: pagesize,
      page: page
    },
    success: function(res) {
      cb(res.data)
    }
  })
}
// 获取视频详情
export function getVideoDetail(id, cb) {
  wx.request({
    url: URL + '/getvideodetail?',
    data: {
      id: id
    },
    success: function(res) {
      cb(res.data)
      console.log(res.data)

    }
  })
}
// 获取banner列表
export function getBannerList(num, cb) {
  wx.request({
    url: URL + '/GetBannerList?',
    data: {
      count: num
    },
    success: function(res) {
      cb(res.data)
    }
  })
}
export function getBannerListPromise(num) {
  return new Promise(function(resolve, reject) {
    wx.request({
      url: URL + '/GetBannerList?',
      data: {
        count: num
      },
      success: function(res) {
        resolve(res.data)
      },
      fail: function(res) {
        reject(res);
      }
    })
  })
}
// 获取微视觉新闻列表
export function getNewsList(pagesize, page, cb) {
  wx.request({
    url: URL + '/GetNewslist?',
    data: {
      pagesize: pagesize,
      page: page
    },
    success: function(res) {
      cb(res.data)
    }
  })
}
// 获取微视觉新闻详情
export function getNewsDetail(id, cb) {
  wx.request({
    url: URL + '/GetNewsDetail?',
    data: {
      id: id
    },
    success: function(res) {
      cb(res.data)
    }
  })
};
// 发表评论
export function addComment(vid, topicid, openid, toopenid, content, cb) {
  wx.request({
    url: URL + '/AddComment?',
    method: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    data: {
      vid: vid,
      topicid: topicid,
      openid: openid,
      toopenid: toopenid,
      content: content
    },
    success: function(res) {
      cb(res.data)
    }
  })
}
// 用户点赞
export function commentLike(cid, cation, cb) {
  wx.request({
    url: URL + '/CommentLike?',
    methid: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    data: {
      cid: cid,
      like: cation
    },
    success: function(res) {
      console.log(cid)
      console.log(cation)
      console.log(cb)
      cb(res.data);
    }
  })
}
// 提交用户信息
export function updateUserInfo(options, cb) {
  // console.log(App)
  wx.request({
    url: URL + '/UpdateUserInfo?',
    method: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    data: options,
    success: function(res) {
      // console.log(res.data)
      cb(res.data)
    }
  })
}
// 记录观看次数
export function VideoWatch(videoId) {
  wx.request({
    url: URL + '/VideoWatch?',
    method: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    data: {
      id: videoId
    }
  })
}
// 用户给视频点赞
export function VideoLike(videoId, cation, cb) {
  console.log(wx.getStorageSync('token'));
  wx.request({
    url: URL + '/VideoLike?',
    method: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    data: {
      id: videoId,
      like: cation
    },
    success: function(res) {
      cb(res.data)
      console.log('会解决');
    }
  })
}
// 获取用户点赞动态
export function getUserLikeVideoList(pagesize, page, cb) {
  wx.request({
    url: URL + '/GetUserLikeVideoList?',
    method: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    data: {
      pagesize: pagesize,
      page: page
    },
    success: function(res) {
      // console.log(res);
      cb(res.data);
    }
  })
}
// 用户收藏
export function Videosc(videoId, cation, cb) {
  console.log(wx.getStorageSync('token'));
  wx.request({
    url: URL + '/VideoFav?id=xxx&fav=true',
    method: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    data: {
      fav:true,
      id: videoId,
      like: cation
    },
    success: function(res) {
      cb(res.data)
      console.log('会解决来来来');
    }
  })
}




// 获取用户发表主体评论的动态
export function getUserCommentList(pagesize, page, cb) {
  wx.request({
    url: URL + '/GetUserCommentList?',
    method: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    data: {
      pagesize: pagesize,
      page: page
    },
    success: function(res) {
      cb(res.data);
    }
  })
}
// 获取某个主题评论下的所有评论
export function getSingleCommentList(cid, pagesize, page, cb) {
  wx.request({
    url: URL + '/GetSingleCommentList?',
    data: {
      cid: cid,
      pagesize: pagesize,
      page: page
    },
    success: function(res) {
      cb(res.data)
    }
  })
}
// 获取视频评论列表
export function getCommentList(vid, pagesize, page, cb) {
  wx.request({
    url: URL + '/GetCommentList?',
    data: {
      vid: vid,
      pagesize: pagesize,
      page: page
    },
    success: function(res) {
      cb(res.data);
    }
  })
}
// 用户发布个性签名
export function publishSign(content, cb) {
  wx.request({
    url: URL + '/PublishSign?',
    method: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    data: {
      content: content
    },
    success: function(res) {
      cb(res.data);
    }
  })
}
// 获取用户个性签名
export function getSign(cb) {
  wx.request({
    url: URL + '/GetSign?',
    method: "POST",
    header: {
      'content-type': 'application/x-www-form-urlencoded',
      'Authorization': 'Bearer ' + wx.getStorageSync('token')
    },
    success: function(res) {
      cb(res.data);
    }
  })
}
